#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

#include "securec.h"
#include "treeUtils.h"
int minDepth(struct TreeNode *root) {
    if (root == NULL) {
        return 0;
    }

    if (root->left == NULL && root->right == NULL) {
        return 1;
    }
    int min_depth = INT_MAX;
    if (root->left) {
        printf("left depth =%d\n", min_depth);
        min_depth = fmin(minDepth(root->left), min_depth);
    }
    if (root->right) {
        printf("right depth =%d\n", min_depth);
        min_depth = fmin(minDepth(root->right), min_depth);
    }
    return min_depth + 1;
}

int main()
{
    setbuf(stdout, 0);
    char str[] = "[3,9,20,null,null,15,7]";
    printf("%s\n", "start strtok string.");
    int count = 0;
    char retStrArr[100][10] = {0};
    getNum(str, retStrArr, &count);
    int numArr[9] = {0};
    for (int i = 0; i < count; ++i) {
        printf("%s\n", retStrArr[i]);
        numArr[i] = atoi(retStrArr[i]);
    }
    printf("%s\n", "end strtok string.");

    struct TreeNode *root = malloc(sizeof(struct TreeNode));
    root->val = numArr[0];
    root->left = NULL;
    root->right = NULL;
    bfsBuildTree(root, numArr, count);
    numArr[4] = 0;
    struct TreeNode *root1 = malloc(sizeof(struct TreeNode));
    root1->val = numArr[0];
    root1->left = NULL;
    root1->right = NULL;
    bfsBuildTree(root1, numArr, count);
    int ret = minDepth(root);
    printf("%d", ret);
}


